﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.Drawing.Imaging;
using System.IO;
using ThoughtWorks.QRCode.Codec;
using ThoughtWorks.QRCode.Codec.Data;
using ThoughtWorks.QRCode.Codec.Util;
using System.Text.RegularExpressions;
using System.Collections;

namespace FormsAppT8
{
    public partial class BQFROMCK : Form
    {

        //dbconn db = new dbconn();

        public BQFROMCK()
        {
            InitializeComponent();
            //comboBox1.SelectedIndex=0;
            bdmain();
            bddetail();
        }
      
        //清单界面绑定
        public void bdmain()
        {
            bqzk();
            string sql = "";
            string table = "";

            sql = "select WarehouseId as 仓库编号,WarehouseName as 仓库名称 from stkwarehouse";

            table = "stkwarehouse";
        
            dataGridView1.Rows.Clear();
            dataGridView1.Columns.Clear();
            dbconn db = new dbconn();
            dataGridView1.Rows.Clear();
            db.bdlm(sql, table, dataGridView1);
            dataGridView2.Rows.Clear();
            dataGridView2.Columns.Clear();
        }

        //明细界面绑定
        public void bddetail()
        {
            bqzk();
            string sql = "";
            string table = "";
            string ckbh = "";
            if (dataGridView1.SelectedRows.Count > 0)
            {

                ckbh = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            }
            sql = "select RowNo as 序号,PlaceId as 储位编号,PlaceName as 储位名称 from stkWareHousePlace where WarehouseId='"+ckbh+"'";
            table = "stkWareHousePlace";
                dataGridView2.Rows.Clear();
                dataGridView2.Columns.Clear();
                dbconn db = new dbconn();
                dataGridView2.Rows.Clear();
                db.bdlm(sql, table, dataGridView2);
        }

        //二维码生成
        public void ewmsc()
        {

            string data = dataGridView2.SelectedRows[0].Cells[1].Value.ToString();
                //pid + bh + "|" + textBox15.Text + "|" + textBox4.Text + "|" + textBox16.Text + "|" + textBox2.Text + "|" +( Convert.ToDouble(textBox5.Text)*1000).ToString();
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            //设置编码模式 
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            //设置编码测量度
            qrCodeEncoder.QRCodeScale = 2;
            //设置编码版本
            qrCodeEncoder.QRCodeVersion = 8;
            //设置编码错误纠正 
            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;

            Image image;
            //生成二维码图片
            image = qrCodeEncoder.Encode(data, Encoding.ASCII); //Encoding.UTF8);

            pictureBox2.Image = image;
        }

        //标签信息显示
        public void bqxx()
        {
            

        }

        //标签内容置空
        public void bqzk()
        {
            label50.Text = "";
            label16.Text = "";
        }

        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            Bitmap _NewBitmap = new Bitmap(300, 300);
            panel5.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height));
            e.Graphics.DrawImage(_NewBitmap, 0, 0, _NewBitmap.Width, _NewBitmap.Height);

            //Pen p = new Pen(System.Drawing.Color.FromArgb(255, System.Drawing.Color.Black),1); //线条颜色和粗细
            //Pen pp = new Pen(System.Drawing.Color.Black,0.3F);
            //Font MyFont1 = new Font("微软雅黑", 10);
            //Font MyFont2 = new Font("微软雅黑", 13);

           

            ////100*120
            //int xS = 10, xs1 = 40, yS = 5, h = 10, ys1 = 50, ys2 = 60;

            //e.Graphics.PageUnit = GraphicsUnit.Millimeter;   //位置度量单位设为毫米
            //e.Graphics.TranslateTransform(0F, 0F);  //偏移量

            ////画表格横线
            //e.Graphics.DrawLine(p, new Point(5, xs1-3), new Point(95, xs1 - 3));
            //e.Graphics.DrawLine(pp, new Point(5, xs1 - 3+  h * 2), new Point(95, xs1 - 3 + h * 2));
            //e.Graphics.DrawLine(pp, new Point(5, xs1 - 3 + h * 3), new Point(95, xs1 - 3 + h * 3));
            //e.Graphics.DrawLine(pp, new Point(5, xs1 - 3 + h * 4), new Point(95, xs1 - 3 + h * 4));
            //e.Graphics.DrawLine(pp, new Point(5, xs1 - 3 + h * 5), new Point(95, xs1 - 3 + h * 5));
            //e.Graphics.DrawLine(pp, new Point(5, xs1 - 3 + h * 6), new Point(95, xs1 - 3 + h * 6));

            ////画表格竖线 
            ////e.Graphics.DrawLine(p, new Point(yS, xS), new Point(yS, xE));

            ////二维码
            //e.Graphics.DrawImage(pictureBox2.Image, xS, yS, 25, 25);
            ////二维码编号
            //e.Graphics.DrawString(label32.Text, MyFont1, Brushes.Black, yS + 25, 30);

           
        }

        private void printDocument2_PrintPage(object sender, PrintPageEventArgs e)
        {

        }

        private void FormT8BQ_Load(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
          
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bdmain();
            bddetail();
        }


        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

      

     

        private void vistaButton1_Click(object sender, EventArgs e)
        {
            ewmsc();
           // if (textBox19.Text == "") { MessageBox.Show("请选择打印份数", "提示信息"); }
          //  else if (Convert.ToInt16(textBox19.Text) > 0)
           // {
           //     for (int q1 = 0; q1 < Convert.ToInt16(textBox19.Text); q1++)
           //     {
                    //设置打印时横向还是纵向
                    //printDocument1.PrinterSettings.Copies = Convert.ToInt16(textBox10.Text);
                    printDocument1.DefaultPageSettings.Landscape = false;
                    printDocument1.DefaultPageSettings.Margins = new Margins(20, 20, 20, 0);
                    printDocument1.Print();
                    dbconn db = new dbconn();
                    //db.sqlcommand("update capMembership set cu_tmcs='" + (Convert.ToInt16(label46.Text) + 1).ToString() + "' where userid='" + label27.Text + "'");
                    ewmsc();
            //    }
            //}
        }

        

        private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            bddetail();
            label50.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            label16.Text = "";
            ewmsc();
        }

   
        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            bddetail();
        }

        private void dataGridView2_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView2.SelectedRows.Count > 0)
            {
               //textBox11.Text=dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
               //textBox18.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
               //textBox15.Text = dataGridView2.SelectedRows[0].Cells[1].Value.ToString();
               //textBox17.Text = dataGridView2.SelectedRows[0].Cells[2].Value.ToString();
              //textBox2.Text = dataGridView2.SelectedRows[0].Cells[3].Value.ToString();

                label50.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                label16.Text = dataGridView2.SelectedRows[0].Cells[2].Value.ToString();
                ewmsc();
                bqxx();
            }

        }

    }
}
